<?php

class MailUtil
{
	/**
	 * Send email using Smtp send mail object.
	 *
	 * @param String $fromEmail
	 * @param String $toEmail
	 * @param String $subject
	 * @param String $cc
	 * @param String $bcc
	 * @param String $body
	 * @param Boll $htmlemail
	 */
	public static function Send($fromEmail, $toEmail, $subject, $cc, $bcc, $body, $htmlemail=false)
	{
		if ($toEmail == "")
		{
			throw new Execption("Destination Email was not provided");
		}

		if ($fromEmail == "")
		{
			throw new Execption("Source Email for was not provided");
		}
		
		$context = Context::getInstance();

		//Adjust for UTF8 Enconding
		$fromEmail = utf8_decode($fromEmail);
		$toEmail = utf8_decode($toEmail);
		$subject = utf8_decode($subject);
		$body = utf8_decode($body);

		// Write the users message to the body of the email
		/*
		$body .= "\n\n--------\n" .
		"eMail sent from site " . $context->ContextValue("SERVER_NAME") . " at " . date("Y-m-d H:i:s") .
		"\nuser " . $context->ContextValue("Remote_Host") .
		"\nengine " . $context->Version() .
		"\nxhtmlstudio.com";
		*/
		
		$headers = "X-Mailer: XMLStudio.net" . "\n";
		//$headers .= "X-Host: " .$context->ContextValue("SERVER_NAME"). "\n";
		$headers .= "From: ".$fromEmail."\n";

		// Send the message
		if($htmlemail)
		{
			$headers .= "MIME-Version: 1.0\n";
			$headers .= "Content-type: text/html; charset=iso-8859-1\n";
		}
		mail($toEmail, $subject, $body, $headers);

		if($cc != "")
		{
			mail($cc, $subject, $body, $headers);
		}
		if($bcc != "")
		{
			mail($bcc, $subject, $body, $headers);
		}
	}
}

?>